#include "mylistphotos.h"
#include <QDrag>
#include <QMimeData>
#include <QDragMoveEvent>
#include <QDragLeaveEvent>
#include <QDragEnterEvent>
#include "collagewindow.h"


MyListPhotos::MyListPhotos(CollageWindow *W,int w,int h,QWidget *parent):QListWidget(parent)
{
    QRect rect(QPoint(20,40),QSize(w,h));
    setGeometry(rect);
    setViewMode(IconMode);
    setIconSize(QSize(120,120));
    setSelectionMode(MultiSelection);
    setAcceptDrops(true);

    labelDrop = new QLabel("Glissez vos images ou dossier\ndans cette zone pour les ajouter !",this);
    QRect rect2(QPoint((w/2)-labelDrop->width(),(h/2)-(labelDrop->height())),QSize(250,40));
    labelDrop->setGeometry(rect2);
    labelDrop->setStyleSheet("QLabel {""font-size:15px;""}");

    //lien vers la fenetre principal
    window=W;
}

/*
 *  DropEvent : lorsque l'on déplace une image sur la liste
 */
void MyListPhotos::dropEvent(QDropEvent *de)
{

    if(de->mimeData()->hasUrls())
    {
        foreach(QUrl url,de->mimeData()->urls())
        {
            window->addPhoto(url.toString(),true);
        }
    }

    window->on_update_delete();

    //Attention : si erreur pendant l'ajout , le message d'erreur est ecrasé

    window->showMessage("");

    this->setStyleSheet("QListWidget {""background-color: white;""}");

}
void MyListPhotos::dragMoveEvent(QDragMoveEvent *de)
{
    de->accept();

    this->setStyleSheet("QListWidget {""background-color: LightGreen;""}");

    window->showMessage("Glissez vos photos ici !");
}
void MyListPhotos::dragLeaveEvent(QDragLeaveEvent *)
{
    window->showMessage("");

    this->setStyleSheet("QListWidget {""background-color: white;""}");
}

void MyListPhotos::dragEnterEvent(QDragEnterEvent *event)
{
    event->acceptProposedAction();
}
